package com.zhang;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.springframework.boot.configurationprocessor.json.JSONArray;
import org.springframework.boot.configurationprocessor.json.JSONObject;

public class GeoLocation {

    private static final String API_KEY = "a580c4cf62ff2a74c00af9cc1874fff2"; // 替换为你的API密钥

    public static void main(String[] args) {

    }

    public static String getGeoLocation(String latitude, String longitude) throws Exception {
        String url = "https://restapi.amap.com/v3/geocode/regeo?location=" + longitude + "," + latitude + "&key=" + API_KEY;
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuilder response = new StringBuilder();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        return response.toString();
    }
}
